package com.yihen.controller;

import com.yihen.dto.Result;
import com.yihen.pojo.Doctor;
import com.yihen.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.print.Doc;
import java.util.ArrayList;

@RestController
@RequestMapping("/doctors")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    /**
     * 获取所有医生信息
     *
     * @return
     * @author 懿痕
     * @time 2022/10/23 20:02
     */
    @GetMapping("/all")
    public Result getAllDoctors() {
        return doctorService.getAllDoctor();
    }

    /**
     * 添加医生信息
     *
     * @param doctor 医生对象
     * @return com.yihen.dto.Result
     * @author 懿痕
     * @time 2022/10/23 20:51
     */
    @PostMapping("/add")
    public Result addDoctor(@RequestBody Doctor doctor) {
        return doctorService.addDoctor(doctor);
    }

    /**
     * 修改一条医生信息
     *
     * @param doctor 医生对象
     * @return int
     * @author 懿痕
     * @time 2022/10/23 20:56
     */
    @PostMapping("/update")
    public Result updateDoctorById(@RequestBody Doctor doctor) {
        return doctorService.updateDoctorById(doctor);
    }

    /**
     * 根据身份证号删除医生
     *
     * @param id 医生身份证号
     * @return int
     * @author 懿痕
     * @time 2022/10/23 21:34
     */
    @GetMapping("/delete/{id}")
    public Result deleteDoctorById(@PathVariable long id) {
        // TODO 删除关联数据
        return doctorService.deleteDoctorById(id);
    }

    // 条件查询
    @PostMapping("/get/condition")
    public Result getDoctorByCondition(@RequestBody Doctor doctor) {
        return doctorService.getDoctorByCondition(doctor);
    }


    // 根据id批量删除医生信息
    @PostMapping("/delete/ids")
    public Result deleteDoctorsByIds(@RequestBody ArrayList<Long> ids) {
        return doctorService.deleteDoctorsByIds(ids);
    }

    // 根据id获取医生信息
    @GetMapping("/get/id/{id}")
    public Result getDoctorById(@PathVariable long id) {
        return doctorService.getDoctorById(id);
    }
}
